﻿using System.Collections;
using System.Collections.Generic;

namespace Miao.ML
{
	public class ListData : GenericReferenceObjectData, IEnumerable<WinMLData>, IEnumerable
	{
		internal readonly List<WinMLData> dataList = new List<WinMLData>();

		public override bool isNone => dataList.Count == 0;

		public override bool isGenericType => true;

		public sealed override DataType type => DataType.List;

		public WinMLData this[int index] => dataList[index];

		public void AddElement(WinMLData element)
		{
			dataList.Add(element);
		}

		public void RemoveElement(WinMLData element)
		{
			dataList.Remove(element);
		}

		public override IEnumerable<WinMLData> GetSubData()
		{
			foreach (WinMLData data in dataList)
			{
				yield return data;
			}
		}

		public override string ToString()
		{
			string text = string.Format("{0}{1}{2}{3}", base.qualifiedName, '&', base.isNull ? "null" : base.referenceID.ToString(), '[');
			if (dataList.Count > 0)
			{
				foreach (WinMLData data in dataList)
				{
					text += $"{data},";
				}
				text = text.Remove(text.Length - 1, 1);
			}
			return text + "]";
		}

		public IEnumerator<WinMLData> GetEnumerator()
		{
			return dataList.GetEnumerator();
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return dataList.GetEnumerator();
		}
	}
}
